<include file="Public:header" />
<script type="text/javascript" src="{$Think.TP_CKFINDER}/ckfinder.js"></script>
<script type="text/javascript">
var divId=10;
var maxPic='{$maxPic}';
BrowseServer=function(obj){
	if($('#adpic').val()!=''){
		alert("最多上传图片" + maxPic + "张图片!请先删除当前图片!");
		return;
	}
	var finder = new CKFinder(); 
	finder.basePath = '{$Think.TP_CKFINDER}/'; 
	finder.startupPath = 'Images:/Watermark/';
	finder.selectActionFunction = SetFileField;
	finder.selectThumbnailActionFunction = ShowThumbnails;
	finder.popup();
}
SetFileField=function(fileUrl,data){
	var sFileName = this.getSelectedFile().name;	
	setView(fileUrl,data,sFileName);
}
ShowThumbnails=function(fileUrl,data)
{
	var sFileName = this.getSelectedFile().name;
	setView(fileUrl,data,sFileName);
	return false;
}
setView=function(fileUrl,data,sFileName){
	var arr = new Array();
	var val = $("#adpic").val();
	if(val!=""){
		var tmp = val.split(",");
		if(tmp.length>=1){
			alert("最多上传图片" + maxPic + "张图片!");
			return false;
		}
		for(var i=0,j=0;i<tmp.length;i++){
			if(tmp[i]==fileUrl){
				alert("您选择的图片已存在!");
				return false;
			}
			if(tmp[i]!=""){
			    arr[j]=tmp[i];
				j++;
			}
		}	
		arr.push(fileUrl);
		var arr = arr.join(",");
		$("#adpic").val(arr);
	}else{
		$("#adpic").val(fileUrl);
	}
	var thumbid = "thumb"+divId;
	var inputid = "input"+divId;
	var tpl='<div class="thumb" id="'+thumbid+'">' +
				'<img class="thumbimg" src="' + fileUrl + '" style="max-width:150px; max-height:150px;"/>' +
				'<div class="caption">' +
					'<input type="hidden" id="' + inputid + '" value="'+ fileUrl +'">' + 
					'<a href="' + data["fileUrl"] + '" target="_blank" class="fl">' + sFileName + '</a> ' +
					'<div onclick="delPic(\'' + thumbid + '\', \'' + inputid + '\')" class="ui-state-default ui-corner-all fl noboder" style="border:none;"><span class="ui-icon ui-icon-circle-minus fl"></span><font class="fl">删除<font></div>' +
				'</div>' +
			'</div>';			
	$("#thumbnails").append(tpl);
	$('#preview').css("display","");
	$("#prompt").css("display","none");
	divId++;
}
delPic=function(divid,inputid){
	var val = $("#adpic").val();
	var arr = val.split(",");
	var input = $("#"+inputid).val();
	arr.splice($.inArray(input,arr),1);
	var arr = arr.join(",");
	$("#adpic").val(arr);
	$("#"+divid).remove();
	if(arr=="")$("#prompt").css("display",""); 
}
$(function(){
    $('#addPart').validate({
        errorPlacement: function(error, element){
            $(element).next('.field_notice').hide();
            $(element).after(error);
        },
        success:function(label){
            label.addClass('right').text('OK!');
        },
        rules : {
            watermark : {
                required : true
            }								
        },
        messages : {
            watermark : {
                required : '不能为空'
            }
        }	
    });
});
</script>
<div id="content">
	<div id="main">
    	<div class="pad20">
			<div id="tabs">            
                <ul>
               		 <li><a href="#tabs-1">{$tabs}</a></li>
                     <li><a href="#tabs-2">测试</a></li>
                </ul>              
                <div id="tabs-1">
                    <form id="addPart" method="post" action="__APP__/Sysdo/watermark/">               
                        <table border="0" cellpadding="0" cellspacing="0">
                        	 <tr style="height:50px">
                                <td>水印方式：</td>
                                <td>
                                	<input id="type" name="type" type="radio" value="0" <if condition="$res['type'] eq 0">checked="checked"</if>/><span>不加水印</span>
                                    <input id="type" name="type" type="radio" value="1" <if condition="$res['type'] eq 1">checked="checked"</if>/><span>图片</span>
                                    <input id="type" name="type" type="radio" value="2" <if condition="$res['type'] eq 2">checked="checked"</if>/><span>文字</span>
                                </td>
                             </tr>	
                             <tr>   
                                <td>水印图片：</td>
                                <td>
                                <input type="hidden" id="adpic" name="adpic" value="{$res['adpic'][0]}"/>
                                <input class="button" type="button" name="upimgBtn" id="upimgBtn" onclick="BrowseServer(this);" value="上传图片" />
                                </td>
                             </tr> 
                             <tr>
                                <td>&nbsp;</td>
                                <td style="padding:10px 0;">
                                    <if condition="empty($res['adpic'])">
                                        <div id="preview" style="display:none;">
                                            <div id="thumbnails"></div>
                                        </div>
                                        <div id="prompt" style="display:;">
                                            <div class="ui-state-default ui-corner-all fl noboder" style="border:none;"><span class="ui-icon ui-icon-alert fl"></span></div>
                                            <div class="fl">
                                                请选择水印图片!
                                            </div>    
                                        </div>  
                                     <else />   
                                        <div id="preview">
                                            <div id="thumbnails">
                                            <volist name="res['adpic']" id="vo" key="k">
                                                <?php
                                                    $e = explode("/",$vo);
                                                    $e = end($e);
                                                ?> 	
                                                <div class="thumb" id="thumb{$k}">
                                                    <img class="thumbimg" src="{$vo}" style="max-width:150px; max-height:150px;">
                                                    <div class="caption">
                                                        <input type="hidden" id="input{$k}" value="{vo.adpic}">
                                                            <a href="{$vo}" target="_blank" class="fl">{$e}</a> 
                                                            <div onclick="delPic('thumb{$k}', 'input{$k}')" class="ui-state-default ui-corner-all fl noboder" style="border:none;"><span class="ui-icon ui-icon-circle-minus fl"></span><font class="fl">删除<font></font></font></div></div></div>
                                            </volist>    
                                            </div>
                                        </div>
                                        <div id="prompt" style="display:none;">
                                            <div class="ui-state-default ui-corner-all fl noboder" style="border:none;"><span class="ui-icon ui-icon-alert fl"></span></div>
                                            <div class="fl">
                                                请选择水印图片!
                                            </div>    
                                        </div>                         	
                                     </if>       
                                </td>
                             </tr>  
                           <tr style="height:50px;">   
                              <td>水印文字：</td>
                              <td><input id="writing" name="writing" type="text" class="w500" value="{$res['writing']}"/><label class="field_notice w200"><span class="red">*</span>必选</label></td>
                           </tr>
                           <tr style="height:50px; display:none;">   
                              <td>水印文字颜色：</td>
                              <td><input id="color" name="color" type="text" class="w500" value="{$res['color']}"/><label class="field_notice"></label></td>
                           </tr>
                           <tr>
                              <td colspan="2"><input class="button" type="submit" value="执行" /></td>
                           </tr>
                        </table>
                    </form>
                </div>   
                <div id="tabs-2">
                	<table border="0" cellpadding="0" cellspacing="0">
                    	<tr>
                        	<td>测试：</td>
                        	<td>{$test}</td>
                        </tr>
                    </table>
                </div>                              
			</div>  
        </div>
	</div>
</div>            
                
<include file="Public:footer" />    